package cn.tedu.charging.order.controller;


import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.order.mqtt.MqttProducer;
import cn.tedu.charging.order.service.OrderService;
import cn.tedu.charging.order.pojo.param.OrderAddParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "订单模块")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @ApiOperation(value = "创建订单")
    @PostMapping("/create")
    public JsonResult<String> createOrder(@RequestBody OrderAddParam orderAddParam){
        log.debug("创建订单: 入参:{}",orderAddParam);

        log.debug("创建订单，调用createOrder入参:{}",orderAddParam);
        String orderNo =orderService.createOrder(orderAddParam);
        log.debug("创建订单，调用createOrder入参:{},出参:{}",orderAddParam,orderNo);
        /*JsonResult<String> jsonResult=new JsonResult<>();
        jsonResult.setCode(2000);
        jsonResult.setMessage("创建成功");
        jsonResult.setData(orderNo);
        return jsonResult;*/
        JsonResult<String> result = JsonResult.ok(orderNo, "创建订单");
        log.debug("创建订单，入参:{},出参:{}",orderAddParam,result);
        return result;
    }
}
